package changceilingcolor003;

import java.util.ArrayList;
import java.util.HashMap;

import toxi.geom.Vec3D;


public class AreaGrid
{

	public AreaGrid(int cols, int rows)
	{
		for(int i =0; i< cols; ++i)
		{
			ArrayGrid.put(i, new HashMap<Integer,ArrayList<Actors>>());
			for(int j=0; j< rows;++j)
			{
				ArrayGrid.get(i).put(j, new ArrayList<Actors>());					
			}
		}
	}
	public ArrayList<Actors> GetActorsInArea(int x, int y)
	{
		try
		{
			return ArrayGrid.get(x/10).get(y/10);	
		}
		catch (Exception e) {
			// TODO: handle exception
			int x1=0;
		}
		return new ArrayList<Actors>();
	}
	
	public void Clear()
	{
		for(int i =0; i< ArrayGrid.size(); ++i)
		{
			
			for(int j=0; j< ArrayGrid.get(i).size();++j)
			{
				ArrayGrid.get(i).get(j).clear();					
			}
		}
	}
	public void AddActors(Actors actor)
	{
		Vec3D loc = actor.GetLocation();
		try
		{
		ArrayGrid.get(((int)loc.x)/10).get(((int)loc.y)/10).add(actor);
		}
		catch (Exception e) {
			int x = 0;
			++x;
			// TODO: handle exception
		}
	}
	
	HashMap<Integer, HashMap<Integer,ArrayList<Actors>>> ArrayGrid = new HashMap<Integer, HashMap<Integer,ArrayList<Actors>>>() ;	
}
